package com.pp.service.impl;

import com.pp.bean.GovGoodsImage;
import com.pp.bean.GovGoodsInfo;
import com.pp.mapper.GovGoodsImageMapper;
import com.pp.service.GovGoodsImageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pp.util.Respons.ResponseUtil;
import com.pp.util.upload.UploadFile;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileNotFoundException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商品详情图 服务实现类
 * </p>
 *
 * @author 张子艺
 * @since 2019-04-02
 */
@Service
public class GovGoodsImageServiceImpl extends ServiceImpl<GovGoodsImageMapper, GovGoodsImage> implements GovGoodsImageService {

    @Override
    public  Map<String, Object> saveGoodManyImage(MultipartFile file,  GovGoodsImage goodsImage ) {
        try {
            String url= UploadFile.fileUpload(file) ;
            goodsImage.setImageUrl(url);
            if(save(goodsImage)){
                return ResponseUtil.getSuccessMap("保存成功",goodsImage.getId()+"");
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return ResponseUtil.getExceptionMap();
        }
        return ResponseUtil.getExceptionMap();
    }

    @Override
    public int updateRelacation(Long relacationId,List<Long> ids) {
        return baseMapper.updateRelacation(relacationId,ids);
    }

    @Override
    public List<GovGoodsImage> findGoodsImage(GovGoodsImage govGoodsImage) {
        return baseMapper.findGoodsImage(govGoodsImage);
    }
}
